package com.huan;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Test4_TimeClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost",10003);
        System.out.println("连接成功"+socket);
        //接受来自服务器的信息，用输入流
        try (InputStream inputStream = socket.getInputStream()){
            byte[] bytes = new byte[1024];
            int length = -1;
            System.out.println("客户端等待服务端的响应");
            while((length=inputStream.read(bytes,0,bytes.length))!=-1){
                String string = new String(bytes,0,length);
                System.out.println("服务器的响应:"+string);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("客户端断开与服务器的连接");
        socket.close();
    }
}
